<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>${name_china}管理列表</title>
<%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>                
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
	
    <span class="field-cont">
        <span class="field-cont-title">昵称/ID</span>
        <input type="text" class="summer-input" id="id" />
    </span>
    <span class="field-cont">
        <span class="field-cont-title">用户手机</span>
        <input type="text" class="summer-input" id="userPhone"/>    
    </span>
    <span class="field-cont">
        <span class="field-cont-title">用户来源</span>
        <input type="text" class="summer-input" id="laiyuan"/>    
    </span>
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
	    <col width="20%">
	    <col width="20%">
	    <col width="20%">
	    <col width="15%">
	    <col width="20%">
	    <col width="20%">
	    <col width="30%">
	    <thead>
		    <tr>
		        <th>用户来源</th>
		        <th>创建时间</th>
		        <th>昵称/ID</th>
		        <th>手机号</th>
		        <th>角色</th>
		        <th>拉黑时间</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
	//请求url
	var CONST_URL = {
		GET_BLACK_LIST: basePath + "${common_url}getBlackList",
		DEL_BLACK: basePath + "${common_url}delBlack",
		RESTORE: basePath + "${common_url}restore",
		INIT_MAIN : basePath + "${common_url}init"
	};
	
    var  permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#id').val('');
        	$('#userPhone').val('');
			$('#laiyuan').combobox('clear');
        	reloadTable();
        });
        
        $('#laiyuan').combobox({
            valueField : 'code',
            textField : 'name',
            url : COMMON_URL.getCode + '?type=T_DM_T_USERS_MALL_LAIYUAN'
        });
        
       createTable();
		$('#goBack').on('click', backMain);    
		//删除
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:delBlack"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL_BLACK + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
		
		//还原
		$('#t-wrap').on('click', 'a[data-permit="${name_english}:restore"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要还原选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.RESTORE + "?id=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '还原成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
       
    });
    function backMain() {
		window.location.href = CONST_URL.INIT_MAIN;
		}
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"id": trimSpace($('#id').val()),
            		"userPhone": trimSpace($('#userPhone').val()),
					"laiyuan": $('#laiyuan').combobox('getValue')
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.GET_BLACK_LIST,
    			param: {
    				"id": trimSpace($('#id').val()),
            		"userPhone": trimSpace($('#userPhone').val()),
					"laiyuan": $('#laiyuan').combobox('getValue')
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'laiyuan'
    		     },
    		     {
    		    	 field:'createTime'
    		     },
    		     {
    		    	 render: function (rowData) {
    		    		 return '<p>'+ rowData.userNickName +'</p>'+'<br/>'
    		    		 		+'<p>'+rowData.id+'</p>';
    		    	 }
    		     },
    		     {
    		    	 field: 'userPhone'
    		     },
    		     {
    		    	 field: 'type'
    		     },
    		     {
    		    	 field: 'setBlackTime'
    		     },   
    		     {
						render : function(rowData) {
							return $.funcbar({
										data : permission, //请求的数据
										type : 'text', //类型
										display : 2, //显示数量
										permit : [
												'${name_english}:restore',
												'${name_english}:delBlack'
												 ]
									//需要的权限按钮
									});
						}
					}
    	    ]
    	});
    }   
</script>
</body>
</html>